package cz.idsv.web.mvc.model.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * Product Entity.
 * 
 * @author Jan Borzensky
 */

@Entity(name = "Product")
@Table(name = "PRODUCT")
public class ProductEntity implements Serializable {

	private static final long serialVersionUID = -8712872333957386182L;

	private Integer id = null;
	private String name = null;
	private String description = null;

	/**
	 * Gets id (primary key).
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}

	/**
	 * Sets id (primary key).
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * Gets name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets name.
	 */
	@Column(name = "NAME")
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets description.
	 */
	@Column(name = "DESCRIPTION")
	public String getDescription() {
		return description;
	}

	/**
	 * Sets description.
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Returns a string representation of the object.
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();

		sb.append(this.getClass().getName() + "-");
		sb.append("  id=" + id);
		sb.append("  name=" + name);
		sb.append("  description=" + description);

		return sb.toString();
	}

	/**
	 * Returns a hash code value for the object.
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		result = prime * result + ((id == null) ? 0 : id.hashCode());
		
		result = prime * result
				+ ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());

		return result;
	}

	/**
	 * Indicates whether some other object is equal to this one.
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final ProductEntity other = (ProductEntity) obj;

		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}

		if (description == null) {
			if (other.description != null) {
				return false;
			}
		} else if (!description.equals(other.description)) {
			return false;
		} 
		return true;
	}

}
